#include <iostream>
#include <vector>
#include <cstdio> 
#include <queue>

#define in read()
#define fi first
#define se second
#define pb push_back

using namespace std;

typedef long long ll;
typedef double db;
typedef vector < int >  vec;
typedef pair < int , int > pii;

int read() {
  int x = 0; bool f = 0; char ch = getchar(); while(!isdigit(ch)) f |= ch == '-',ch = getchar();
  while(isdigit(ch)) x = x * 10 + (ch ^ 48),ch = getchar(); return f ? -x : x;
}

const int N = 5e5 + 10;

int n,K;
int a[N],b[N];
ll tot;

bool check(int mid) {
    priority_queue < pii , vector < pii > , greater < pii > > q; int cnt = 0; tot = 0;
    for(int i = 1;i <= n;i++) {
	q.push({ a[i] - mid , 0 });
	if(q.top().fi + b[i] <= 0) {
	    tot += q.top().fi + b[i]; if(!q.top().se) cnt++; q.pop();
	    q.push({ -b[i] , 1});
	}
    } return cnt >= K;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("1.in","r",stdin);
#endif
    n = in,K = in; for(int i = 1;i <= n;i++) a[i] = in; for(int i = 1;i <= n;i++) b[i] = in;
    int l = 0,r = 2e9;
    while(l <= r) {
	int mid = ((ll) l + r) >> 1;
	if(check(mid)) r = mid - 1;
	else l = mid + 1; 
    }
    check(l); printf("%lld\n",tot + (ll) K * l); return 0;
} 
